<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class Check
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse)  $next
     * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
     */
    //固定格式，固定方法，固定参数
    public function handle(Request $request, Closure $next)
    {
        //拦截代码
        if ($request->get('id') != 1){
            return redirect(url('api/login'));
        }

        //固定返回，让其继续往下执行主体代码
        return $next($request);
    }
    public function terminate($request,$response){
        echo '<br>http相应完毕再调用我';
    }
}
